<template>
    <div class>
        <div class="title-row">
            <div class="flex item-center">
                <div class="label-line"></div>
                <span class="title">取号情况</span>
            </div>
            <div class="line"></div>
        </div>
        <ul class="take-content">
            <li @click="onClickItem(item,index)" v-for="(item,index) in dataList" :key="index" class="take-li">
                <i class="circle"></i>
                <div class="cell-label">
                    <div class="text-over">
                        <span class="take-num">【{{item.rankNum}}】</span>
                        <span class="db-num">{{item.handleInfoName}}</span>
                    </div>
                </div>
                <span class="take-time">
                    {{item.pastTime}}
                </span>
            </li>
            <div v-if="!dataList.length" class="no-data">
                <img src="../../assets/no-data.png" alt="">
            </div>
        </ul>
    </div>
</template>

<script>
import { tyGetTakeNumList } from "../../config/api.js";
import { getDateStr } from "../../utils/index.js";
import Pubsub from "../../utils/pubsub";
export default {
    data() {
        return {
            filter: 1, //1表示累计，2表示今日
            dataList: [],
            getDateStr
        };
    },
    methods: {
        /**
         * 点击取号情况
         */
        onClickItem(item, index) {
            if (index == 0) {
                let {
                    handleInfo,
                    handleInfoName,
                    handlePersonName,
                    handlePersonCardNum,
                    createTime,
                    rankNum,
                    cardStartTime,
                    cardEndTime,
                    telNo,
                } = item;
                let obj = {
                    rankNum,
                    takeTime: createTime,
                    handleInfo,
                    telNo,
                    handleInfoName,
                    handlePersonName,
                    handlePersonCardNum,
                    handlePersonStartTime: cardStartTime,
                    handlePersonEndTime: cardEndTime,
                    id: item.id
                };
                Pubsub.publish("showRegisterDialog", {
                    type: "ywsl",
                    handleType: "workbench",
                    ...obj
                });
            }
        },
        getList() {
            tyGetTakeNumList({ pageNum: 1, pageSize: 999 }).then(
                (result = {}) => {
                    let { rows } = result;
                    rows.map(item => {
                        item.pastTime = getDateStr(item.createTime);
                    });
                    this.dataList = rows;
                    this.totalPage = result.totalPage;
                    this.timer = setInterval(this.setPastTime, 1000 * 60);
                }
            );
        },
        /**
         * 换算过去时间
         */
        setPastTime() {
            let tamp = new Date().getTime();
            this.dataList.map(item => {
                item.pastTime = getDateStr(item.createTime);
            });
        }
    },
    created() {
        this.getList();
        this.pubsub_token1 = Pubsub.subscribe("BUSINESS_TAKE_NUM", () => {
            this.getList();
        });
    },
    destroyed() {
        this.pubsub_token1 && Pubsub.unsubscribe(this.pubsub_token1);
        this.timer && clearInterval(this.timer);
    }
};
</script>

<style lang = "scss" scoped>
@import "../../css/unifyAcceptWorkbench.scss";

.take-content {
    margin: 25px 0;
    height: 259px;
    overflow: auto;
    .take-li {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 14px;
        cursor: pointer;
        &:last-child {
            margin-bottom: 0;
        }
        font-size: 16px;
    }
    .circle {
        height: 4px;
        width: 4px;
        border-radius: 4px;
        background: #000;
        display: block;
        margin-right: 20px;
    }
    .take-num {
        color: #ffaa00;
    }
    .take-time {
        font-size: 14px;
        color: #ffaa00;
        span {
            font-size: 14px;
            color: #888888;
        }
    }
}
</style>